﻿<%@ Page Title="Cungmuanao.com - Thêm/cập nhật sản phẩm" Language="C#" MasterPageFile="~/Admin/Admin.master" 
    AutoEventWireup="true" ValidateRequest="false" CodeFile="AddEditProduct.aspx.cs" Inherits="Admin_AddEditProduct" %>
<%@ Import Namespace="DTO" %>
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>
<%@ Register assembly="CKEditor.NET" namespace="CKEditor.NET" tagprefix="CKEditor" %>
<%@ Register src="../Controls/FileUpload2Control.ascx" tagname="FileUpload2Control" tagprefix="uc1" %>
<%@ Register src="../Controls/FileUploadFullPath.ascx" tagname="FileUploadFullPath" tagprefix="uc2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="LeftContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<%--<script type="text/javascript" src="../js/nicEdit.js"></script>
<script type="text/javascript">
    bkLib.onDomLoaded(function () {
        nicEditors.allTextAreas()
    });
</script>--%>

    <div class="title">
  <asp:Literal runat="server" ID="lblNewProduct" Text="Thêm sản phẩm mới" />
  <asp:Literal runat="server" ID="lblEditProduct" Text="Cập nhật sản phẩm" Visible="false" />
</div>
<div class="body"> 
<ul style="list-style-type: circle">
    <li>
        <asp:HyperLink ID="HyperLink1" runat="server" Text="quản lý danh mục sản phẩm" NavigateUrl="~/Admin/ManageDepartments1.aspx"></asp:HyperLink>
    </li>
</ul> 
<ul style="list-style-type: circle">
    <li>
        <asp:HyperLink ID="HyperLink3" runat="server" Text="quản lý loại sản phẩm" NavigateUrl="~/Admin/ManageDepartments.aspx"></asp:HyperLink>
    </li>
</ul>
<ul style="list-style-type: circle">
    <li>
        <asp:HyperLink ID="HyperLink2" runat="server" Text="quản lý sản phẩm" NavigateUrl="~/Admin/ManageProducts.aspx"></asp:HyperLink>
    </li>
</ul>
<hr />   
<p></p>
<asp:DetailsView ID="dvwProduct" Width="100%" runat="server"  AutoGenerateRows="False" 
        DataKeyNames="ID" DataSourceID="objCurrProduct"
        DefaultMode="Insert" HeaderText="chi tiết sản phẩm" BackColor="White" 
        BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" 
        CellPadding="3" ondatabound="dvwProduct_DataBound" 
        onitemcreated="dvwProduct_ItemCreated" 
        onmodechanged="dvwProduct_ModeChanged" 
        ondatabinding="dvwProduct_DataBinding" 
        oniteminserting="dvwProduct_ItemInserting" 
        onitemupdating="dvwProduct_ItemUpdating">
         <FieldHeaderStyle Width="100px" />
       <FooterStyle BackColor="White" ForeColor="#000066" />
       <RowStyle ForeColor="#000066" />
       <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
      <Fields>
         <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
            SortExpression="ID" />
         <asp:BoundField DataField="AddedDate" HeaderText="Ngày tạo" InsertVisible="False"
            ReadOnly="True" SortExpression="AddedDate" HtmlEncode="false" DataFormatString="{0:f}" />
         <asp:BoundField DataField="AddedBy" HeaderText="Người tạo" InsertVisible="False" ReadOnly="True"
            SortExpression="AddedBy" />
            
         <asp:TemplateField HeaderText="Loại sản phẩm" SortExpression="DepartmentID">
            <ItemTemplate>
                <asp:Label runat="server" ID="lblDepartment" Text='<%#Eval("DepartmentID") %>' />
            </ItemTemplate>
            <EditItemTemplate>
                <asp:UpdatePanel ID="up1" runat="server">
                <ContentTemplate>
<%--                    <asp:DropDownList ID="ddlDepartments1" runat="server"
                        DataSourceID="objAllDepartments1" AutoPostBack="True"
                    DataTextField="Title" DataValueField="ID" Width="30%" 
                        ondatabound="ddlDepartments1_DataBound">
                    </asp:DropDownList>
                    <asp:ObjectDataSource ID="objAllDepartments1" runat="server" 
                        TypeName="BLL.Store.Departments1" 
                        SelectMethod="ListDepartments1"  >
                    </asp:ObjectDataSource>--%>
                    
                    <asp:DropDownList runat="server"  ID="ddlDepartments"  DataSourceID="objAllDepartments"
                      DataTextField="Title" DataValueField="ID"  Width="30%" /><%--SelectedValue='<%# Bind("DepartmentID") %>'--%>
                    <asp:ObjectDataSource runat="server" ID="objAllDepartments" TypeName="BLL.Store.Department" SelectMethod="ListDepartments">
                    </asp:ObjectDataSource>
                    </ContentTemplate>
                 </asp:UpdatePanel>
            </EditItemTemplate>
         </asp:TemplateField>
         
         <asp:TemplateField HeaderText="Tên sản phẩm" SortExpression="Title">
            <ItemTemplate>
               <asp:Label ID="lblTitle" runat="server" Text='<%# Eval("Title") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtTitle" runat="server" Text='<%# Bind("Title") %>' Width="100%" MaxLength="256"/>
               <asp:RequiredFieldValidator ID="valRequireTitle" runat="server" ControlToValidate="txtTitle" SetFocusOnError="true"
                  Text="Tên Sản Phẩm không được bỏ trống" ToolTip="Tên Sản Phẩm không được bỏ trống" Display="Dynamic">
                  </asp:RequiredFieldValidator>
            </EditItemTemplate>
         </asp:TemplateField>
                  
        <asp:TemplateField HeaderText="Giá gốc" SortExpression="UnitPrice">
            <ItemTemplate>
                <asp:Label runat="server" ID="lblUnirPrice" Text='<%#Eval("RoundUnitPrice")%>' />
            </ItemTemplate>
            <EditItemTemplate>
                <asp:TextBox ID="txtUnitPrice" runat="server" Text='<%# Bind("UnitPrice") %>' Width="60%" MaxLength="256"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="valRequireUnitPrice" runat="server" ControlToValidate="txtUnitPrice" SetFocusOnError="true"
                  Text="Giá không được bỏ trống" ToolTip="Giá không được bỏ trống" Display="Dynamic"></asp:RequiredFieldValidator>
               <asp:CompareValidator ID="valUnitPriceType" runat="server" Operator="DataTypeCheck" Type="Currency"
                  ControlToValidate="txtUnitPrice" Text="Giá sản phẩm phải là số nguyên."
                  ToolTip="Giá sản phẩm phải là số nguyên." Display="dynamic" />
            </EditItemTemplate>
         </asp:TemplateField>
         
        <%--<asp:TemplateField HeaderText="Giá" SortExpression="UnitPrice">
            <ItemTemplate>
                <asp:Label runat="server" ID="lblUnirPrice" Text='<%#Eval("UnitPrice")%>' />
            </ItemTemplate>
            <EditItemTemplate>
                <asp:TextBox ID="txtUnitPrice" runat="server" Text='<%# Bind("UnitPrice","{0:0,000}") %>' Width="60%" MaxLength="256"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="valRequireUnitPrice" runat="server" ControlToValidate="txtUnitPrice" SetFocusOnError="true"
                  Text="Giá không được bỏ trống" ToolTip="Giá không được bỏ trống" Display="Dynamic"></asp:RequiredFieldValidator>
               <asp:CompareValidator ID="valUnitPriceType" runat="server" Operator="DataTypeCheck" Type="Currency"
                  ControlToValidate="txtUnitPrice" Text="Giá sản phẩm phải là số nguyên."
                  ToolTip="Giá sản phẩm phải là số nguyên." Display="dynamic" />
            </EditItemTemplate>
         </asp:TemplateField>--%>
         
         <asp:TemplateField HeaderText="Giá khuyến mãi" SortExpression="DiscountPercentage">
            <ItemTemplate>
               <asp:Label ID="lblDiscountPercentage" runat="server" Text='<%# Eval("DiscountPercentage") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtDiscountPercentage" runat="server" Text='<%# Bind("DiscountPercentage") %>' Width="100%" MaxLength="256"></asp:TextBox>
               <%--<asp:RequiredFieldValidator ID="valRequireDiscountPercentage" runat="server" ControlToValidate="txtDiscountPercentage" SetFocusOnError="true"
                  Text="% giảm giá không được bỏ trống." ToolTip="% giảm giá không được bỏ trống." Display="Dynamic"></asp:RequiredFieldValidator>
               <asp:CompareValidator ID="valDiscountPercentageType" runat="server" Operator="DataTypeCheck" Type="Integer"
                  ControlToValidate="txtDiscountPercentage" Text="% giảm giá là dạng số nguyên."
                  ToolTip="% giảm giá là dạng số nguyên." Display="dynamic" />--%>
            </EditItemTemplate>
         </asp:TemplateField>
         
         <asp:TemplateField HeaderText="Ảnh nhỏ" SortExpression="SmallImageUrl">
            <ItemTemplate>
               <asp:Label ID="lblSmallImageUrl" runat="server" Text='<%# Eval("SmallImageUrl") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtSmallImageUrl" runat="server" Text='<%# Bind("SmallImageUrl") %>' Width="100%" MaxLength="256"></asp:TextBox>
            </EditItemTemplate>
         </asp:TemplateField>
         
         <asp:TemplateField HeaderText="Ảnh lớn" SortExpression="FullImageUrl">
            <ItemTemplate>
               <asp:Label ID="lblFullImageUrl" runat="server" Text='<%# Eval("FullImageUrl") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtFullImageUrl" runat="server" Text='<%# Bind("FullImageUrl") %>' Width="100%" MaxLength="256"></asp:TextBox>
            </EditItemTemplate>
         </asp:TemplateField>
         
       <asp:TemplateField HeaderText="Mức độ quan trọng" SortExpression="Quantity">
            <ItemTemplate>
               <asp:Label ID="lblQuantity" runat="server" Text='<%# Eval("Quantity") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtQuantity" runat="server" Text='<%# Bind("Quantity") %>' Width="100%" MaxLength="256"></asp:TextBox>
            </EditItemTemplate>
         </asp:TemplateField>
         
         <%--<asp:TemplateField HeaderText="Hiện ở trang chủ" >
            <ItemTemplate>
               <asp:CheckBox ID="chkIShow" runat="server" Checked='<%# Eval("IsShow") %>' Enabled="False" />
            </ItemTemplate>
            <EditItemTemplate>
               <asp:CheckBox ID="chkIShow" runat="server" Checked='<%# Bind("IsShow") %>' />
            </EditItemTemplate>
         </asp:TemplateField>
         
         <asp:TemplateField HeaderText="Hiện ở sản phẩm mới" >
            <ItemTemplate>
               <asp:CheckBox ID="chkIsNew" runat="server" Checked='<%# Eval("IsNew") %>' Enabled="False" />
            </ItemTemplate>
            <EditItemTemplate>
               <asp:CheckBox ID="chkIsNew" runat="server" Checked='<%# Bind("IsNew") %>' />
            </EditItemTemplate>
         </asp:TemplateField>--%>         
         
         <asp:TemplateField HeaderText="Mô tả" SortExpression="Description">
            <ItemTemplate>
                <asp:Label ID="lblDescription" runat="server" Text='<%# Eval("Description") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>              
               <%--<FCKeditorV2:FCKeditor ID="FCKeditor1" BasePath="~/fckeditor/" runat="server" Value='<%# Bind("Description") %>' 
               ToolbarSet="Simple" Height="300px" Width="100%" />--%> 
               <%--<asp:TextBox ID="FCKeditor1" runat="server" Text='<%# Bind("Description") %>' Rows="5" TextMode="MultiLine" Width="100%" MaxLength="4000"></asp:TextBox>--%>
               <CKEditor:CKEditorControl ID="txtBody" runat="server" Text='<%# Bind("Description") %>'></CKEditor:CKEditorControl>
            </EditItemTemplate>
         </asp:TemplateField>
          <asp:CommandField ButtonType="Image" CancelImageUrl="~/Images/nhaplai.png" 
              CancelText="Nhập  lại" InsertImageUrl="~/Images/themmoi.png" 
              InsertText="Thêm mới" ShowInsertButton="True" ShowEditButton="True"
              UpdateImageUrl="~/Images/capnhat.png" UpdateText="Cập nhật" />         
      </Fields>
      <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
       <EditRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />      
</asp:DetailsView>
<asp:ObjectDataSource runat="server" ID="objCurrProduct" TypeName="BLL.Store.Product" SelectMethod="GetProductByID" InsertMethod="InsertProduct"
    UpdateMethod="UpdateProduct" DeleteMethod="DeleteProduct">
    <SelectParameters>
        <asp:QueryStringParameter Name="productID" QueryStringField="ID" Type="Int32" />
    </SelectParameters>
    <InsertParameters>
         <asp:Parameter Name="departmentID" Type="Int32" />
         <asp:Parameter Name="title" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="CodeProduct" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="Orgin" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="unitPrice" Type="Decimal" />
         <asp:Parameter Name="description" Type="String" />
         <asp:Parameter Name="discountPercentage" Type="Int32" />
         <asp:Parameter Name="smallImageUrl" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="fullImageUrl" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="quantity" Type="Int32" />
         <asp:Parameter Name="isshow" Type="Boolean" />
         <asp:Parameter Name="isnew" Type="Boolean" />
    </InsertParameters>
    <UpdateParameters>
         <asp:Parameter Name="id" Type="Int32" />
         <asp:Parameter Name="departmentID" Type="Int32" />
         <asp:Parameter Name="title" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="CodeProduct" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="Orgin" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="unitPrice" Type="Decimal" />
         <asp:Parameter Name="description" Type="String" />
         <asp:Parameter Name="discountPercentage" Type="Int32" />
         <asp:Parameter Name="smallImageUrl" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="fullImageUrl" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="quantity" Type="Int32" />
         <asp:Parameter Name="isshow" Type="Boolean" />
         <asp:Parameter Name="isnew" Type="Boolean" />
    </UpdateParameters>
    <DeleteParameters>
        <asp:Parameter Name="id" Type="Int32" />
    </DeleteParameters>
    </asp:ObjectDataSource>
    <br />
    Sản phẩm :
    <uc1:FileUpload2Control ID="FileUpload2Control1" runat="server" />

    <br />
    Mô tả :
    <uc2:FileUploadFullPath ID="FileUploadFullPath" runat="server" />

</div>   
<div class="bottom"></div>
</asp:Content>

